import 'package:app/page/container/login/base_login_state.dart';
import 'package:app/page/container/login/desktop/desktop_login_view_builder.dart';
import 'package:app/page/container/login/moblie/moblie_login_view_builder.dart';
import 'package:app/page/container/login/tablet/tablet_login_view_builder.dart';
import 'package:app/responsive.dart';
import 'package:flutter/material.dart';

class LoginView extends StatefulWidget {
  const LoginView({super.key});
  @override
  State<StatefulWidget> createState() {
    return LoginViewState();
  }
}

class LoginViewState extends State<LoginView>
    with BaseLoginViewState, SingleTickerProviderStateMixin {
  late TabController _tabController;
  late DesktopLoginViewBuilder _desktopLoginViewBuilder;
  late TabletLoginViewBuilder _tabletLoginViewBuilder;
  final MobileLoginViewBuilder _mobileLoginViewBuilder =
      MobileLoginViewBuilder();

  @override
  void initState() {
    _tabController = TabController(length: 2, vsync: this);
    // 监听点击事件
    _tabController.addListener(() {
      currentPage = _tabController.index;
      setState(() {});
    });
    _desktopLoginViewBuilder = DesktopLoginViewBuilder(_tabController);
    _tabletLoginViewBuilder = TabletLoginViewBuilder(_tabController);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(children: [
      getBodgetBodyView(context),
      Positioned(
          left: 12,
          top: 12,
          child: Container(
            width: 42,
            height: 42,
            decoration: const BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(42)),
                border: Border.symmetric(
                    vertical: BorderSide(color: Color(0xffdcdcdc), width: 1),
                    horizontal:
                        BorderSide(color: Color(0xffdcdcdc), width: 1))),
            child: TextButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: const Icon(
                Icons.arrow_back,
                color: Colors.black,
              ),
            ),
          )),
    ]);
  }

  //http://qiniuyun.xiaotuzhi.top/sign_in_bg-bbc515a9c2e7734807ea281b9b2ab380.png
  Widget getBodgetBodyView(BuildContext context) {
    if (Responsive.isDesktop(context)) {
      return _desktopLoginViewBuilder.build(context, this);
    } else if (Responsive.isTablet(context)) {
      return _tabletLoginViewBuilder.build(context, this);
    } else {
      return _mobileLoginViewBuilder.build(context, this);
    }
  }
}
